package com.mp.approvalreq.servlet.other.module;

import com.mp.approvalreq.entity.dto.TemplateDTO;
import com.mp.approvalreq.service.SelectApprovalServicePrx;
import com.mp.approvalreq.servlet.AbstractServlet;
import com.mp.approvalreq.util.ServiceUtils;
import com.mp.user.entity.User;
import com.plusmoney.message.SuccessMsg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 获取审批流中有我，抄送人也有我(不含多身份)的审批模板:离职交接时使用
 */
@WebServlet("/getMyRequestFlowAndCc")
public class GetMyRequestFlowAndCc extends AbstractServlet {
	
	private static final Logger logger = LoggerFactory.getLogger(GetMyRequestFlowAndCc.class);
	
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		try {
			User user = getReqUser(req);
			
			Integer contactId = Integer.valueOf(req.getParameter("contactId"));
			logger.info("输入json:{}", contactId);
			
			SelectApprovalServicePrx selectApprovalService = ServiceUtils.getSelectApprovalServicePrx();
			List<TemplateDTO> templateDTOs = selectApprovalService.getMyRequestFlowAndCc(user.getCompanyId(), contactId);
			
			String msg = SuccessMsg.getDefaultMsg(templateDTOs);
			
			logger.info("返回json:{}", msg);
			
			printJson(resp, msg);
		} catch (Throwable e) {
			onThrowable(req, resp, e);
		}
	}
	
}

